package com.ruoyi.webs.hzhelp.advice.controller;

import java.util.List;

import com.ruoyi.webs.hzhelp.advice.domain.HzHelpAdvice;
import com.ruoyi.webs.hzhelp.advice.service.IHzHelpAdviceService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投诉建议Controller
 * 
 * @author ruoyi
 * @date 2021-10-03
 */
@Controller
@RequestMapping("/advice")
public class HzHelpAdviceController extends BaseController
{
    private String prefix = "advice";

    @Autowired
    private IHzHelpAdviceService hzHelpAdviceService;

    @RequiresPermissions("system:advice:view")
    @GetMapping()
    public String advice()
    {
        return prefix + "/advice";
    }

    /**
     * 查询投诉建议列表
     */
    @RequiresPermissions("system:advice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HzHelpAdvice hzHelpAdvice)
    {
        startPage();
        List<HzHelpAdvice> list = hzHelpAdviceService.selectHzHelpAdviceList(hzHelpAdvice);
        return getDataTable(list);
    }

    /**
     * 导出投诉建议列表
     */
    @RequiresPermissions("system:advice:export")
    @Log(title = "投诉建议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HzHelpAdvice hzHelpAdvice)
    {
        List<HzHelpAdvice> list = hzHelpAdviceService.selectHzHelpAdviceList(hzHelpAdvice);
        ExcelUtil<HzHelpAdvice> util = new ExcelUtil<HzHelpAdvice>(HzHelpAdvice.class);
        return util.exportExcel(list, "投诉建议数据");
    }

    /**
     * 新增投诉建议
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存投诉建议
     */
    @RequiresPermissions("system:advice:add")
    @Log(title = "投诉建议", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HzHelpAdvice hzHelpAdvice)
    {
        return toAjax(hzHelpAdviceService.insertHzHelpAdvice(hzHelpAdvice));
    }

    /**
     * 修改投诉建议
     */
    @GetMapping("/edit/{ID}")
    public String edit(@PathVariable("ID") String ID, ModelMap mmap)
    {
        HzHelpAdvice hzHelpAdvice = hzHelpAdviceService.selectHzHelpAdviceByID(ID);
        mmap.put("hzHelpAdvice", hzHelpAdvice);
        return prefix + "/edit";
    }

    /**
     * 修改保存投诉建议
     */
    @RequiresPermissions("system:advice:edit")
    @Log(title = "投诉建议", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HzHelpAdvice hzHelpAdvice)
    {
        return toAjax(hzHelpAdviceService.updateHzHelpAdvice(hzHelpAdvice));
    }

    /**
     * 删除投诉建议
     */
    @RequiresPermissions("system:advice:remove")
    @Log(title = "投诉建议", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hzHelpAdviceService.deleteHzHelpAdviceByIDs(ids));
    }
}
